package com.xinheyun.demo.leetcode;

import java.util.ArrayDeque;
import java.util.Deque;
import org.springframework.util.CollectionUtils;
//import org.apache.commons.collections4.CollectionUtils;
//import org.springframework.cglib.core.CollectionUtils;

/**
 * @description: TODO
 * @author: Sarah
 * @modified By: Sarah
 * @date: Created in 2021/8/7 17:50
 * @version:v1.0
 */
public class test232 {

    public static void main(String[] args) {

    }


}


class MyQueue {

    Deque<Integer> deque1;
    Deque<Integer> deque2;

    /**
     * Initialize your data structure here.
     */
    public MyQueue() {
        deque1 = new ArrayDeque();
        deque2 = new ArrayDeque();
    }

    /**
     * Push element x to the back of queue.
     */
    public void push(int x) {
        deque1.addFirst(x);
    }

    /**
     * Removes the element from in front of queue and returns that element.
     */
    public int pop() {
        if (!CollectionUtils.isEmpty(deque2)) {
            return deque2.removeFirst();
        }

        if (!CollectionUtils.isEmpty(deque1)) {
            for (Integer q : deque1) {
                deque2.addFirst(deque1.getFirst());
            }
            return deque2.removeFirst();
        }
        return -1;
    }

    /**
     * Get the front element.
     */
    public int peek() {
        if (!CollectionUtils.isEmpty(deque2)) {
            return deque2.getFirst();
        }

        if (!CollectionUtils.isEmpty(deque1)) {
            for (Integer q : deque1) {
                deque2.addFirst(deque1.removeFirst());
            }
            return deque2.getFirst();
        }
        new ArrayDeque<>();
        return -1;
    }

    /**
     * Returns whether the queue is empty.
     */
    public boolean empty() {
        if(deque1.isEmpty()&&deque2.isEmpty()){
            return true;
        }
        return false;
    }
}